home *** CD-ROM | disk | FTP | other *** search
-
- #include "cb.h"
-
- int cmp_name();
-
- namefind(cp,name,pagit,printcall)
- FILE *cp;
- char *name;
- int pagit;
- int *(printcall)();
- {
- char *p;
- char *d;
- caddr_t mi;
- char *list[8];
- char **l;
- char fmtname[128];
- char buf[512];
- char c;
- int idsize;
- FILE *fp;
- int n;
- int ns;
- struct nind key;
- struct nind *idx;
- struct nind *found;
- struct nind *end;
- struct stat st;
- int IS = sizeof(struct nind);
-
- if ((fp=fopen("nlist.ndx","r")) == NULL)
- {
- printf("Error opening nlist.ndx\n");
- exit(1);
- }
- fstat(fileno(fp),&st);
- if ((mi = (caddr_t)mmap(NULL,st.st_size,PROT_READ,MAP_SHARED,
- fileno(fp),NULL)) == (caddr_t)NULL)
- {
- fprintf(stderr,"Error - mmap index file\n");
- exit(1);
- }
- fclose(fp);
-
- idsize = st.st_size/IS;
- idx = (struct nind *)mi;
-
- p = name;
- while (*p)
- {
- switch (*p)
- {
- case ',':
- case '.':
- case '\'':
- *p = ' ';
- break;
- default:
- break;
- }
- p++;
- }
- if ((n = tokenize(name,list,8)) == NULL)
- return(0);
-
- memset(key.name,0,sizeof(key.name));
- memset(fmtname,0,sizeof(fmtname));
- l = list;
- while (*l)
- {
- strcat(fmtname,*l++);
- strcat(fmtname," ");
- }
- p = strrchr(fmtname,' ');
- *p = '\0';
-
- strncpy(key.name,fmtname,sizeof(key.name)-1);
- p = key.name;
- while (*p)
- *p++ = toupper(*p);
-
- found = (struct nind *)bsearch((char *)(&key),
- (char *)idx, idsize, sizeof(struct nind), cmp_name);
-
- if (!found)
- {
- munmap(mi,st.st_size);
- return(0);
- }
-
- end = idx + IS;
- ns = strlen(key.name);
- while ( found && !strncmp(key.name,found->name,ns))
- found--;
- found++;
-
- n = 0;
- while ( found && (found != end) && !strncmp(key.name,found->name,ns))
- {
- fseek(cp,found->pos,SEEK_SET);
- fread(buf,sizeof(buf),1,cp);
- p = buf;
- while (*p != '\n')
- *p++;
- *p = '\0';
-
- pcall(buf,printcall);
- found++;
- n++;
- if (pagit && (n%5 == 0))
- if ((c=n_any_key(1,printcall)) == 'Q')
- break;
- }
- munmap(mi,st.st_size);
- return(n);
- }
-
- cmp_name(i1,i2)
- struct nind *i1, *i2;
- {
- int r;
- int n = strlen(i1->name);
-
- r = (strncmp(i1->name,i2->name,n));
- return (r);
- }
-
-
- n_any_key(q,printcall)
- int q;
- int *(printcall)();
- {
- char c;
-
- if (q)
- printcall("<Press any key to continue or Q)uit ==> ");
- else
- printcall("<Press any key to continue> ");
-
- c = toupper((char)getchar());
- printcall("\n\r");
- return(c);
- }
-
-
-